import { createStore } from "redux";

const defState: IRootState = {
  toasStData: {
    toastShow: false,
    toastMessage: "test",
    toastType: "error",
  },
};

const reducer = (state: IRootState = defState, action: IRootAction) => {
  state = JSON.parse(JSON.stringify(state));

  // 根据 action.type 进行判断
  switch (action.type) {
    case "SHOW_TOAST":
      const data = action.payload as IToastPayload;
      state.toasStData.toastMessage = data.toastMessage;
      state.toasStData.toastShow = true;
      state.toasStData.toastType = data.toastType;
      break;
    case "HIDE_TOAST":
      state.toasStData.toastShow = false;
  }
  return state;
};

const store = createStore(reducer);

export default store;
